use serde::{Deserialize, Serialize};

use common::page::{BasePage, PageData};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CreateRole {
    pub role_name: Option<String>,
    pub role_code: Option<String>,
    pub desc: Option<String>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SetRoleResource {
    pub role_id: Option<i64>,
    pub resource: Option<Vec<i64>>,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct RolePage {
    pub page_data: Option<PageData>,
    pub role_name: Option<String>,
    pub role_code: Option<String>,
    pub desc: Option<String>,
}

impl BasePage for RolePage {
    fn get_page_data(&self) -> PageData {
        match self.page_data.clone() {
            None => {
                PageData{
                    page: 1,
                    page_size: 10,
                    sorter: None,
                }
            }
            Some(page_data) => {
                page_data
            }
        }
    }
}
